﻿using System;
using System.Linq;
using System.Collections.Generic;

using Microsoft.Drawing;
using System.Drawing;

namespace Spencen.Mobile.UI.Controls
{
    public class NavigationButtonBar : ButtonBar
    {
        private static Brush _arrowBrush = new SolidBrush( Color.LightGray );
        private static Pen _arrowPen = new Pen( Color.Gray );

        public NavigationButtonBar( IDrawingHost host ) : base( host )
        {
            ShowRightArrow = true;
        }

        public bool ShowRightArrow { get; set; }

        protected override void OnRender( GraphicsContext context )
        {
            base.OnRender( context );

            int offsetY = (int)( 12 * context.Graphics.DpiY / 96f );
            int offsetX = (int)( 12 * context.Graphics.DpiX / 96f );
            int arrowWidth = (int)( 12 * context.Graphics.DpiX / 96f );

            var arrowPoints = new Point[] { 
                new Point( Size.Width - offsetX - arrowWidth, offsetY ), 
                new Point( Size.Width - offsetX, Size.Height / 2 ),
                new Point( Size.Width - offsetX - arrowWidth, Size.Height - offsetY ) };

            var transformedArrowPoints = context.TransformedPoints( arrowPoints );

            // Draw the right arrow if required
            if ( ShowRightArrow )
            {
                context.Graphics.FillPolygon( _arrowBrush, transformedArrowPoints );
                context.Graphics.DrawPolygon( _arrowPen, transformedArrowPoints );
            }
        }
    }
}
